//
//  InheritVC.swift
//  swiftDemo
//
//  Created by mac on 2017/3/21.
//  Copyright © 2017年 毕小强. All rights reserved.
//

import UIKit

class InheritVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        //基类
        class Vehicle{
            var currentSpeed = 0.0
            var description:String {
                return "traveling at \(currentSpeed) miles per hour"
            }
            
            func makeNoise()  {
                
            }
        }
        let someVechicle = Vehicle()
        print(someVechicle.description)
        
        //子类
        class Bicycle:Vehicle{
            var hasBasket = false
            
        }
        let bicycle = Bicycle()
        bicycle.hasBasket = true
        print("Bicycle:\(bicycle.description)")
        
        class Tandem:Bicycle{
             var currentNumberOfPassengers = 0
            let child = 1
            
        }
        let tandem = Tandem()
        tandem.hasBasket = true
        tandem.currentNumberOfPassengers = 2
        tandem.currentSpeed = 22.0
        print("Tandem:\(tandem.description)")
        
        //重写
        final class Wheel:Tandem{
            final var wheelCount : Int
            
            override init() {
                wheelCount = 100
            }
            
            override var description: String{
               return super.description + "厉害了"
            }
            
            override var hasBasket: Bool{
                didSet{
                    print(hasBasket)
                }
            }
            
            
        }
        let wheel = Wheel()
        print(wheel.description)
        wheel.hasBasket = true
        print(wheel.hasBasket)
        
        /*
         *      final终点标记符,被标记的属性、方法、类不能再被重写
         *      final用来阻止重写
         **/
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
